<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            height: 30px;
            width: 0;
            background-color: #d81d1d;
            line-height: 30px;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <script>
        app = document.querySelector('#app');

        function handle() {
            let i = 0;
            (function run() {
                app.innerHTML = i;
                app.style.width = i + 'px';
                if (++i <= 100) {
                    setTimeout(function () {
                        run();
                    }, 30)
                }
            })()
            console.log(i)
        }
        // function handle() {
        //     let i = 0;
        //     timeRanges = setInterval(function () {
        //         app.innerHTML = i;
        //         app.style.width = ++i + 'px';
        //         // console.log(i)
        //         if (i > 100) {
        //             // console.log(i)
        //             clearInterval(timeRanges)
        //         }
        //     }, 30)
        // }

        handle();
    </script>
</body>

</html>